// JavaScript Document
function explode (delimiter, string, limit) {
     var emptyArray = { 0: '' };
    
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||        delimiter === false ||
        delimiter === null ) {
        return false;
    }
     if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;    }
}
function implode (glue, pieces) {
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];                tGlue = glue;
            }
            return retVal;
        }
    }    else {
        return pieces;
    }
}
function get_my_url(needed,arrneeded){

	var arr = explode('/',needed);
	
	for(var j=0;j<arr.length;j++){
	  var arrtemp = explode('~',arr[j]);
	  for(var i=0;i<arrneeded.length;i++){
	  		 if(arrneeded[i]==arrtemp[0]){
			   arr[j]="";
			 }
	  }
	}
	var n=-1;
	var arrnew=[];
	for(var k=0;k<arr.length;k++){
		
		if(arr[k]!=""){
			n = n +1 ;
			arrnew[n] = arr[k];
		}
		
		if(arr[k]=="http:"){
			arrnew[k] = arr[k]+"/";
		}
		
	}
	var newurl = implode('/',arrnew);

	return newurl+"/";

}
function changetype(type,myurl){
	
	url = get_my_url(myurl,['cat','type']);

	if(type!=""){type = 'type~'+type+'/1';}
	
	openurl = url+type;

	window.location.href = openurl;
	
}
function changecat(cat_id,myurl){

	url = get_my_url(myurl,['cat','']);
	
	if(cat_id>0){ cat_id = 'cat~'+cat_id+'/1'; }
	
	openurl = url+cat_id;

	window.location.href = openurl;
	
}
function changecity(city_id,myurl){
	
	url = get_my_url(myurl,['city','dist']);
	
	if(city_id>0){ city_id = 'city~'+city_id+'/1';}
	
	openurl = url+city_id;

	window.location.href = openurl;
	
}
function changedist(dist_id,myurl){
	
	url = get_my_url(myurl,['dist','']);
	
	if(dist_id>0){ dist_id = 'dist~'+dist_id+'/1';}
	
	openurl = url+dist_id;

	window.location.href = openurl;
	
}
function isearch(myurl){
	
	url = get_my_url(myurl,['search','']);
	
	keyword = document.getElementById('keyword').value;
	
	if(keyword.length<3){	
		alert('Từ khóa tìm kiếm không được nhỏ hơn 2 ký tự')
		return false;
	}
	keyword = keyword.replace(/\~/g,'');
	keyword = keyword.replace(/"/g,'');
	keyword = keyword.replace(/'/g,'');
	
	keysearch = 'search~'+keyword+'/1';
	
	openurl = url+keysearch;

	window.location.href = openurl;
	
}